﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.RoleManage.Controls
{
	public partial class ModifyNavigation : BaseUserControl
	{
		#region property
		/// <summary>
		/// 当前的导航项键值。
		/// </summary>
		public string CurrentKey
		{
			get { return NavigationBar.CurrentKey; }
			set { NavigationBar.CurrentKey = value; }
		}

		/// <summary>
		/// 角色名。
		/// </summary>
		public Guid RoleId
		{
			get { return (Guid)ViewState["RoleId"]; }
			set { ViewState["RoleId"] = value; }
		}
		#endregion

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				BindNavigationData();
				this.DataBind();
			}
		}

		protected void BindNavigationData()
		{
			string queryString = string.Format(@"?RoleId={0}&SiteId={1}", RoleId, SiteId);

			bool disallowUserAccredit = Roles.RoleHasProperty(RoleId, Roles.RolePropertyCode.DisallowUserAccredit);
			bool disallowRoleAccredit = Roles.RoleHasProperty(RoleId, Roles.RolePropertyCode.DisallowRoleAccredit);

			if (!disallowUserAccredit)
				NavigationBar.NavigationItems.Add("AddUsersToRole", new OperationNavigationItem("用户授权", "~/RoleManage/AddUsersToRole.aspx" + queryString));

			if (!disallowRoleAccredit)
			{
				List<ResourceCategory> categorys = ResourceCategories.GetItems();
				foreach (ResourceCategory category in categorys)
				{
					NavigationBar.NavigationItems.Add("Accredit_" + category.CategoryId, new OperationNavigationItem(category.CategoryName, "~/RoleManage/Accredit.aspx" + queryString + "&CategoryId=" + category.CategoryId));
				}
			}
		}
	}
}